<template>
  <el-config-provider :locale="locale">
    <div>
      <RouterView></RouterView>
    </div>
  </el-config-provider>
</template>

<script setup>

import { onMounted, ref, onUnmounted } from 'vue';
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
let locale = zhCn;
let beforeUnloadTime = ref(0)
let gapTime = ref(0)

const beforeunloadHandler = () => {
  beforeUnloadTime.value = new Date().getTime();
}

const unloadHandler = () => {
  gapTime.value = new Date().getTime() - beforeUnloadTime.value;
  //判断是窗口关闭还是刷新
  if (gapTime.value <= 5) {//浏览器关闭
    localStorage.clear()
  }
}

onMounted(() => {
  //监听页面卸载（关闭）或刷新
  window.addEventListener('beforeunload', () => beforeunloadHandler())

  window.addEventListener('unload', () => unloadHandler())
})
</script>

<style lang="scss" scoped></style>